<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DataView</title>
</head>
<body>
  <script>
    const buf = new ArrayBuffer(16);
    const fullDataView = new DataView(buf);

    console.log(fullDataView.byteOffset);  // 0
    console.log(fullDataView.byteLength);  // 16
    console.log(fullDataView.buffer === buf);  // true
  </script>

  <script>
    // 接受一个可选的字节偏移量和字节长度
    const firstHalfDataView = new DataView(buf, 0, 8);
    console.log(firstHalfDataView.byteOffset);  // 0
    console.log(firstHalfDataView.byteLength);  // 8
    console.log(firstHalfDataView.buffer === buf);  // true
  </script>

  <script>
    // 如果不指定，则 DataView 会使用剩余的缓冲
    const secondHalfDataView = new DataView(buf, 8);
    console.log(secondHalfDataView.byteOffset);  // 8
    console.log(secondHalfDataView.byteLength);  // 8
    console.log(secondHalfDataView.buffer === buf);  // true
  </script>
</body>
</html>